import { GameMapUtil } from "../../scene/map/GameMapUtil";
import { Cache } from "../../cache/Cache";
import { JSON } from "../../../../com/mui/serialization/json/JSON";
import { CacheManager } from "../../../../com/gengine/manager/CacheManager";
import { ECareer } from "../../../../Message/Public/ECareer";
import { LadderCareerConfig } from "../../resource/LadderCareerConfig";
import { TSkill } from "../../../../Message/Db/Tables/TSkill";
type int = number;
//class LadderBattlefieldUtil
    
    export  class LadderBattlefieldUtil
    {
        

        public static get isInLadderBattlefield(): Boolean
        {
            return GameMapUtil.curMapState.isLadderBattlefield;
        }

        public static get useLadderBattlefieldShortcutsData(): Boolean
        {
            var loc1=Cache.instance.ladderBattlefield.ladderCareer;
            return isInLadderBattlefield && !(Cache.instance.role.careerBasic == loc1) && !(Cache.instance.role.careerSecond == loc1);
        }

        public static getObjNameByCareer(arg1: int): string
        {
            return LadderBattlefieldUtil.NAME + "_" + arg1 + "_" + Cache.instance.role.playerInfo.playerId;
        }

        public static get shortJsStrByCareer(): string
        {
            var loc1=LadderBattlefieldUtil.getObjNameByCareer(Cache.instance.ladderBattlefield.ladderCareer);
            return JSON.serialize(skillObj.data[loc1]);
        }

        public static set shortJsStrByCareer(arg1: string)
        {
            var loc2=null;
            var loc1=Cache.instance.ladderBattlefield.ladderCareer;
            if (useLadderBattlefieldShortcutsData) 
            {
                loc2 = LadderBattlefieldUtil.getObjNameByCareer(loc1);
                skillObj.data[loc2] = JSON.deserialize(arg1);
                skillObj.flush();
            }
            return;
        }

        public static get skillObj(): Object /* flash.net.SharedObject */
        {
            if (LadderBattlefieldUtil._skillObj == null) 
            {
                LadderBattlefieldUtil._skillObj = CacheManager.instance.getLocal(LadderBattlefieldUtil.NAME);
                if (String(LadderBattlefieldUtil._skillObj.data[LadderBattlefieldUtil.getObjNameByCareer(ECareer._ECareerWarriorD)] == undefined)) 
                {
                    LadderBattlefieldUtil._skillObj.data[LadderBattlefieldUtil.getObjNameByCareer(ECareer._ECareerWarriorD)] = LadderBattlefieldUtil.getDefaultShortJsStrByCareer(ECareer._ECareerWarriorD);
                }
                if (String(LadderBattlefieldUtil._skillObj.data[LadderBattlefieldUtil.getObjNameByCareer(ECareer._ECareerStabber)] == undefined)) 
                {
                    LadderBattlefieldUtil._skillObj.data[LadderBattlefieldUtil.getObjNameByCareer(ECareer._ECareerStabber)] = LadderBattlefieldUtil.getDefaultShortJsStrByCareer(ECareer._ECareerStabber);
                }
                if (String(LadderBattlefieldUtil._skillObj.data[LadderBattlefieldUtil.getObjNameByCareer(ECareer._ECareerIceMage)] == undefined)) 
                {
                    LadderBattlefieldUtil._skillObj.data[LadderBattlefieldUtil.getObjNameByCareer(ECareer._ECareerIceMage)] = LadderBattlefieldUtil.getDefaultShortJsStrByCareer(ECareer._ECareerIceMage);
                }
                if (String(LadderBattlefieldUtil._skillObj.data[LadderBattlefieldUtil.getObjNameByCareer(ECareer._ECareerPriest)] == undefined)) 
                {
                    LadderBattlefieldUtil._skillObj.data[LadderBattlefieldUtil.getObjNameByCareer(ECareer._ECareerPriest)] = LadderBattlefieldUtil.getDefaultShortJsStrByCareer(ECareer._ECareerPriest);
                }
            }
            return LadderBattlefieldUtil._skillObj;
        }

        public static cleanSkillObj(): void
        {
            skillObj.clear();
            return;
        }

        /* internal  */static getDefaultShortJsStrByCareer(arg1: int): Object
        {
            var loc4=0;
            var loc5=null;
            var loc1=LadderCareerConfig.instance.getSkillListByCareer(arg1);
            var loc2=new Object();
            var loc3=loc1.length + 1;
            var loc6=1;
            while (loc6 <= loc3) 
            {
                loc4 = arg1 * 10000 + loc6;
                if (loc6 != 1) 
                {
                    loc5 = loc1[loc6 - 2] as TSkill;
                    loc2[loc4] = {"code": loc5.skillId, "id": loc5.skillId};
                }
                else 
                {
                    loc2[loc4] = {"code": 2000000, "id": 2000000};
                }
                ++loc6;
            }
            return loc2;
        }

        public static getReplaceShortJsStrByCareer(arg1: string): string
        {
            var loc6=0;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            var loc1=arg1;
            var loc2=LadderCareerConfig.instance.getSkillListByCareer(Cache.instance.ladderBattlefield.ladderCareer);
            var loc3=0;
            var loc4=0;
            var loc5=loc2.length;
            while (loc3 < loc5) 
            {
                loc8 = String(TSkill(loc2[loc3]).skillId);
                loc6 = int(loc8.substr(0, (loc8.length - 1)) + "0");
                loc4 = 0;
                while (loc4 < 10) 
                {
                    loc7 = String(loc6 + loc4);
                    if (loc1.indexOf(loc7 + ",") != -1) 
                    {
                        loc9 = new RegExp(loc7, "g");
                        loc1 = loc1.replace(loc9, loc8);
                        break;
                    }
                    ++loc4;
                }
                ++loc3;
            }
            return loc1;
        }

        /* internal */ static /* const */NAME: string="LadderBattlefieldSkill";

        /* internal */ static /* var */_skillObj: Object /* flash.net.SharedObject */;
    }
